<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>LogsPath ALL</title>
</head>
<body>
<h1>LogsPath ALL</h1>
<div id="listLogsPath" style="margin-left:30px;">
    <h3>日志数据</h3>
</div>
</body>
<script type="text/javascript">
    // XMLHttpRequest对象用于在后台与服务器交换数据;
    // IE浏览器: new ActiveXObject("Microsoft.XMLHttp");
    // 其他：new XMLHttpRequest();
    var RootURL = 'http://127.0.0.1:8083/';
    var xhr =  window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
    // 获取所有数据
    function getLogs() {
        var url = RootURL + 'test/logs';
        xhr.open('GET', url, true);
        xhr.onreadystatechange = function () {
            // readyStatus == 4说明请求已经完成
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    //从服务器获得数据
                    var r = xhr.responseText;
                    r = JSON.parse(r);
                    if (r.success) {
                        var list = r.listLogPath;
                        var listLength = list.length;
                        if (listLength > 0) {
                            var html = '';
                            for (var i = 0; i < list.length; i++) {
                                var logName = list[i];
                                html = html + '<h5 onclick="showLog('+i+')" id="log_'+i+'" style="cursor:pointer">'+logName+'</h5>';
                            }
                            var $listLogsPath = document.getElementById('listLogsPath');
                            $listLogsPath.innerHTML = html;
                        }
                    } else {
                        alert('请求失败: ' + r.errMsg);
                    }
                } else {
                    alert("Ajax数据请求失败, status: " + xhr.status);
                }
            } else {
                console.log("Ajax数据请求中, readyState: " + xhr.readyState);
            }
        };
        xhr.send();
    }

    getLogs();

    function showLog(i) {
        var $log = document.getElementById('log_'+i);
        var logName = $log.innerText;
        console.log(logName);
        window.location.href = RootURL + "logs/"+logName;
    }



</script>
</html>